package com.hspedu.spring.component;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;

import javax.annotation.Resource;

@Controller
public class UserController {

    /**
     * 机制：
     * 1、在IOC容器中查找待装配的组件的类型，如果有唯一的bean匹配，则使用该bean装配
     * 2、如果待装配的类型对应的bean在IOC容器中有多个，则使用待装配的属性的属性名作为id值再进行查找，找到就装配，找不到就抛异常
     */
    @Resource(name = "userService200")
    private UserService userService;

    public void sayOk() {
        System.out.println("UserController的sayOk() UserController.userService=" + userService);
        userService.hi();
    }

}


